<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <base href="${basePath }"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="3rd/ligerui/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css"/>
    <script src="3rd/ligerui/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
    <script src="3rd/ligerui/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var openWin;
        var msg = '${param.msg}';
        if(msg=='OK'){
            alert("添加成功！");
        }

        function queryData() {
            manager.setOptions({
                parms: $('#queryForm').serializeArray()
            });
            manager.loadData();
        }
        var examWin, recommendWin, manager;
        $(function() {
            manager = $("#content").ligerGrid({
                checkbox: true,
                columns: [
                    {name:'id',hide:1},
                    { display: '标题', name: 'title', align: 'left', width: 200 },
                    { display: '类型', name: 'type', minWidth: 60 },
                    { display: '状态', name: 'status',  width: 70,align:'left' },
                    { display: '点击次数', name: 'click', width: 60 },
                    { display: '栏目名称', name: 'partName', width: 60},
                    { display: '排序索引', name: 'sort', width: 60 , editor: { type: 'int'}},
                    { display: '创建时间', name: 'created' }
                ], dataAction: 'server',pageSize:20,
                root:"rows",
                record:"total",
                enabledEdit: true,onAfterEdit: f_onAfterEdit,
                url: "${basePath}article/list.shtml",
//                sortName : 'sort',sortOrder:"desc",
                width: '100%',height:'100%',
                toolbar: { items: [
                    { text: '修改', click: function() {
                        var rows = manager.getSelecteds();
                        if (rows.length == 1) {
                            var row = manager.getSelected();
                            openWin = $.ligerDialog.open({ url: '${basePath }article/edit.shtml?id=' + row.id, height: 500, width: 900, showMax: true, isResize: true, title: '修改记录'});
                            openWin.max();
                        } else {
                            $.ligerDialog.question("请选择一条数据！")
                        }
                    }, icon: 'modify' },
                    { line: true },
                    { text: '审核', click: function() {
                        var rows = manager.getSelecteds();
                        if (rows.length > 0) {
                            var artids = "";
                            for (var i = 0; i < rows.length; i++) {
                                var rowsData = rows[i];
                                artids = (artids + rowsData.id + ",");
//                                params.push(rowsData.picid);
                            }
//                            var row = manager.getSelected();
//                            $('#ids').val(row.id);
                            $('#ids').val(artids);
                            examWin = $.ligerDialog.open({ target: $("#examine"),title:'文章审核'});
                        } else {
                            $.ligerDialog.question("请至少选择一条数据进行审核！")
                        }
                    }, icon: 'modify' },
                    { line: true },
                    { text: '推荐', click: function() {
                        var rows = manager.getSelecteds();
                        if (rows.length > 0) {
                            var artids = "";
                            for (var i = 0; i < rows.length; i++) {
                                var rowsData = rows[i];
                                artids = (artids + rowsData.id + ",");
                            }
                            $('#articleIds').val(artids);
                            recommendWin = $.ligerDialog.open({ target: $("#recommend"),title:'推荐位置'});
                        } else {
                            $.ligerDialog.question("请至少选择一条数据进行推荐！")
                        }
                    }, icon: 'modify' },
                    { line: true },
                    { text: '推送', click: function() {
                        $.ligerDialog.question("comeing soon！")
                    }, icon: 'modify' },
                    { line: true },
                    { text: '删除', click: function() {
                        var rows = manager.getSelecteds();
                        if (rows.length > 0) {
                            $.ligerDialog.confirm('确认要删除选择的' + rows.length + '条记录吗？', function (yes) {
                                if (yes) {
                                    var ids = [];
                                    for (var i in rows) {
                                        ids.push(rows[i].id);
                                    }
                                    $.post("article/del.shtml", {id:ids.join(',')}, function(data) {
                                        $.ligerDialog.tip({  title: '提示信息',content:'删除成功！' });
                                        queryData();
                                        setTimeout(function () {
                                            $.ligerDialog.close();
                                        }, 2000);
                                    });
                                }
                            });
                        } else {
                            $.ligerDialog.question("请选择要删除的记录！")
                        }
                    } }
                ]
                }
            });

            $('#queryForm').ligerForm();

            $("#confirm").click(function() {
                var status = $('#examForm input[name=status]:checked');
                if (status.length) {
                    $.post("article/exam.shtml", $('#examForm').serializeArray(), function(data) {
                        examWin.hidden();
                        $.ligerDialog.success('操作成功！', function() {
                            $('#examForm input[name=status]:checked').attr('checked', false);
                            queryData();
                        });
                    });
                } else {
                    examWin.hidden();
                    $.ligerDialog.question("请先选择数据！", function() {
                        examWin.show();
                    });
                }
            });

            $("#recommendConfirm").click(function() {
                var status = $('#recommendForm input[name=recommendId]:checked');
                if (status.length) {
                    $.post("article/recommend.shtml", $('#recommendForm').serializeArray(), function(data) {
                        recommendWin.hidden();
                        $.ligerDialog.success('操作成功！', function() {
                            $('#recommendForm input[name=status]:checked').attr('checked', false);
                            queryData();
                        });
                    });
                } else {
                    recommendWin.hidden();
                    $.ligerDialog.question("请先选择数据！", function() {
                        recommendWin.show();
                    });
                }
            });


            $('#queryBtn').click(function() {
                queryData();
            });

        });

        function f_onAfterEdit(e) {
//            alert(e.record.id + "," + e.record.sort);
            var id = e.record.id;
            var sort = e.record.sort;
            $.post("article/editsort.shtml", {id:id , sort:sort}, function(data) {
                $.ligerDialog.tip({  title: '提示信息',content:'成功保存排序！' });
                queryData();
                setTimeout(function () {
                    $.ligerDialog.close();
                }, 2000);
            });
//            manager.updateCell('Price', e.record.UnitPrice * e.record.Quantity, e.record);
        }

//        $("#partId").ligerComboBox({
//            width: 180,
//            selectBoxWidth: 200,
//            selectBoxHeight: 200, valueField: 'text',treeLeafOnly:false,
//            tree: { url: '../tree/tree.json', checkbox: false }
//        });
    </script>
    <style type="text/css">
        body {
            font-size: 12px;
        }

        .l-table-edit {
        }

        .l-table-edit-td {
            padding: 4px;
        }

        .l-button-submit, .l-button-test {
            width: 80px;
            float: left;
            margin-left: 10px;
            padding-bottom: 2px;
        }

        .l-verify-tip {
            left: 230px;
            top: 120px;
        }
    </style>
    <title>文章列表</title>
</head>
<body>
<form id="queryForm">
    <table cellspacing="3" class="l-table-edit">
        <tr>
            <td>
                <div>标题：</div>
            </td>
            <td>
                <div><input name="title"/></div>
            </td>
            <td>&nbsp;&nbsp;类型：</td>
            <td class="l-table-edit-td">
                <select name="type">
                    <option value="">请选择</option>
                    <option value="A">文章模型</option>
                    <option value="V">视频模型</option>
                    <option value="P">图片模型</option>
                    <option value="I">图集模型</option>
                    <option value="S">分类模型</option>
                </select></td>
            <td>&nbsp;&nbsp;状态：</td>
            <td class="l-table-edit-td"><select name="status">
                <option value="">请选择</option>
                <option value="1">待审核</option>
                <option value="2">审核不通过</option>
                <option value="3">审核通过</option>
                <option value="4">已发布</option>
            </select></td>
            <td>&nbsp;&nbsp;栏目：</td>
            <td class="l-table-edit-td">
                <%--<input type="partId" id="partId"/>--%>
                <select name="partId" id="partId">
                    <option value="">请选择</option>
                    <c:forEach items="${parts}" var="entry">
                        <option value="${entry.key}"
                                <c:if test="${article.partId} eq ${entry.key}">selected="selected"</c:if>> ${entry.value}</option>
                    </c:forEach>
                </select>
            </td>
            <td>&nbsp;&nbsp;<input type="button" id="queryBtn" value="查询"/>
            </td>
        </tr>
    </table>
    </div>
</form>

<div id="content" style="margin:0; padding:0"></div>

<div id="examine" style="margin:5px; display:none;">
    <div>
        <div id="d1">
            <form id="examForm">
                <table>
                    <tr>
                        <td><input type="radio" value="2" name="status" id="s1"/></td>
                        <td><label for="s1">审核不通过</label></td>
                    </tr>
                    <tr>
                        <td><input type="radio" value="3" name="status" id="s2"/></td>
                        <td><label for="s2">审核通过</label></td>
                    </tr>
                    <tr>
                        <td><input type="radio" value="4" name="status" id="s3"/></td>
                        <td><label for="s3">发布文章</label></td>
                    </tr>
                </table>
                <input type="hidden" name="ids" id="ids"/>
            </form>
        </div>
        <br/>
        <input type="button" id="confirm" value="确定" class="l-button"/>
    </div>
</div>

<div id="recommend" style="margin:5px; display:none;">
    <div>
        <div>
            <form id="recommendForm">
                <table>
                    <tr>
                        <td>
                            <c:forEach items="${recommends}" var="entry">
                                <input value="${entry.key}" name="recommendId"
                                       type="checkbox">${entry.value} &nbsp;&nbsp;
                            </c:forEach>
                        </td>
                    </tr>
                </table>
                <input type="hidden" name="articleIds" id="articleIds"/>
            </form>
        </div>
        <br/>
        <input type="button" id="recommendConfirm" value="确定" class="l-button"/>
    </div>
</div>

</body>
</html>